/**
 * 
 */
package com.epcs.subGNuevosNegocios.eci.struts.action.base;

import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 * @author Nicolas Figueroa
 *
 */
public class BaseAction extends DispatchAction{

	/**
	 * Variables
	 */
	//public static Logger logger =
    //    Logger.getLogger(BaseAction.class);

/*	public ResultSet executeQuery(HttpServletRequest request, String query)
	{
		DataSource dataSource;
		Connection connection;
		Statement stmt;
		ResultSet rs;
		try{
			dataSource = getDataSource(request, "dataSourceOracle");
			connection = dataSource.getConnection();
			stmt = connection.prepareStatement(query);
			rs = stmt.executeQuery(query);
			return rs;
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
*/	
/*	public void executeProcedure(HttpServletRequest request, String procedure, String parametros)
	{
		DataSource dataSource;
		Connection connection;
		try{
			dataSource = getDataSource(request, "dataSourceOracle");
			connection = dataSource.getConnection();
			CallableStatement stmtProcedure = connection.prepareCall("");
			
		}catch(Exception e)
		{
			e.printStackTrace();
		}
	}
*/	
	public boolean testSession(HttpServletRequest request){
		HttpSession session = request.getSession();
		
		
		com.epcs.subGNuevosNegocios.eci.to.UsuarioTO usuario;
		
		usuario = (com.epcs.subGNuevosNegocios.eci.to.UsuarioTO) 
					session.getAttribute("usuario");
		if(usuario==null){
			//if(session.isNew()) return false;
			return false;
		}
		return true;
	}
	
	public ActionForward ajaxTestSession (ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){

		
		response.setContentType("text/html");
		ServletOutputStream ouputStream;
		try {
			ouputStream = response.getOutputStream();

			if(this.testSession(request)){
	
				ouputStream.write("TRUE".getBytes());
			}
			else{
				ouputStream.write("FALSE".getBytes());
			}
	        ouputStream.flush();
	        ouputStream.close();
	        
		} catch (IOException e) {
			
			//e.printStackTrace();
		}
		return null;
	}
}
